import { inject, injectable } from "inversify";
import { Event, ConfigurationTarget, EventEmitter, ConfigurationChangeEvent } from "vscode";
import { IWorkspaceService } from "./application/types";
import { FileSystemPaths } from "./platform/fa-paths";
import { IDisposable, IDisposableRegistry, IEQSettings, IInterpreterPathService, InspectInterpreterSettingType, InterpreterConfigurationScope, IPersistentStateFactory, Resource } from "./types";

export const defaultInterpreterPathSetting: keyof IEQSettings = 'defaultInterpreterPath';

@injectable()
export class InterpreterPathService implements IInterpreterPathService {

    public _didChangeInterpreterEmitter = new EventEmitter<InterpreterConfigurationScope>();
    private fileSystemPaths: FileSystemPaths;
    constructor(
        @inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
        @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
        @inject(IDisposableRegistry) disposables: IDisposable[],
    ) {
        disposables.push(this.workspaceService.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this)));
        this.fileSystemPaths = FileSystemPaths.withDefaults();
    }

    public async onDidChangeConfiguration(event: ConfigurationChangeEvent) {
        if (event.affectsConfiguration(`eq.${defaultInterpreterPathSetting}`)) {
            this._didChangeInterpreterEmitter.fire({ uri: undefined, configTarget: ConfigurationTarget.Global });
        }
    }

    public get onDidChange(): Event<InterpreterConfigurationScope> {
        return this._didChangeInterpreterEmitter.event;
    }
    get(resource: Resource): string {
        throw new Error("10Method not implemented.");
    }
    inspect(resource: Resource): InspectInterpreterSettingType {
        throw new Error("11Method not implemented.");
    }
    update(resource: Resource, configTarget: ConfigurationTarget, value: string | undefined): Promise<void> {
        throw new Error("12Method not implemented.");
    }
}